/*
Created By VietRise on 18/6/2014
*/

#include "ScreenHelp.h"
#include "ScreenStart.h"

ScreenHelp::~ScreenHelp()
{
}

ScreenHelp::ScreenHelp()
{
	_screenSize = CCDirector::sharedDirector()->getWinSize();

	createScreen();
	setTouchEnabled(true);
}

CCScene* ScreenHelp::scene()
{
	CCScene* scene = CCScene::create();
	ScreenHelp* layer = new ScreenHelp();
	scene->addChild(layer);
	layer->release();
	return scene;
}

void ScreenHelp::ccTouchesBegan(CCSet* pTouches, CCEvent* event)
{
	CCTouch* touch = (CCTouch*)pTouches->anyObject();
	CCPoint tap = touch->getLocation();
	if (touch)
	{
		if (_btnBack->boundingBox().containsPoint(tap))
		{			
			((CCSprite*)_btnBack->getChildByTag(kSpriteBtnStatePress))->setVisible(true);
		}
	}
}

void ScreenHelp::ccTouchesEnded(CCSet* pTouches, CCEvent* event)
{
	CCTouch* touch = (CCTouch*)pTouches->anyObject();
	CCPoint tap = touch->getLocation();
	if (touch)
	{
		if (_btnBack->boundingBox().containsPoint(tap))
		{
			((CCSprite*)_btnBack->getChildByTag(kSpriteBtnStatePress))->setVisible(false);
			CCScene* newScene = CCTransitionMoveInL::create(0.2f, ScreenStart::scene());
			CCDirector::sharedDirector()->replaceScene(newScene);
		}
	}
}

void ScreenHelp::createScreen()
{
	CCSprite* bgSprite = CCSprite::create("bg_help.png");
	bgSprite->setPosition(ccp(_screenSize.width*0.5f, _screenSize.height*0.5f));
	this->addChild(bgSprite, kBackground);

	_btnBack = CCSprite::createWithSpriteFrameName("btn_back_normal.png");
	_btnBack->setAnchorPoint(ccp(0, 0));
	_btnBack->setPosition(ccp(10, 10));
	this->addChild(_btnBack, kMiddleground);

	CCSprite* sprite = CCSprite::createWithSpriteFrameName("btn_back_press.png");
	sprite->setAnchorPoint(ccp(0, 0));
	sprite->setVisible(false);
	_btnBack->addChild(sprite, kForeground, kSpriteBtnStatePress);
}